package com.disys.facade;

import java.io.Serializable;
import java.util.List;

import com.disys.dao.PersonDAO;
import com.disys.model.Person;

public class PersonFacade implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private PersonDAO personDAO = new PersonDAO();

	public void createPerson(Person person) {
		//personDAO.beginTransaction();
		personDAO.save(person);
		//personDAO.commitAndCloseTransaction();
	}

	public void updatePerson(Person person) {
		//personDAO.beginTransaction();
		Person persistedPerson = personDAO.find(person.getId());
		persistedPerson.setName(person.getName());
		persistedPerson.setAge(person.getAge());
		//personDAO.commitAndCloseTransaction();
	}
	
//	public void deletePerson(Person person){
//		personDAO.beginTransaction();
//		Person persistedPersonWithIdOnly = personDAO.findReferenceOnly(person.getId());
//		personDAO.delete(persistedPersonWithIdOnly);
//		personDAO.commitAndCloseTransaction();
//		
//	}

	public Person findPerson(int personId) {
		//personDAO.beginTransaction();
		Person person = personDAO.find(personId);
		//personDAO.closeTransaction();
		return person;
	}

	public List<Person> listAll() {
		//personDAO.beginTransaction();
		List<Person> result = personDAO.findAll();
		//personDAO.closeTransaction();

		return result;
	}

//	public Person findPersonWithAllDogs(int personId) {
//		personDAO.beginTransaction();
//		Person person = personDAO.findPersonWithAllDogs(personId);
//		personDAO.closeTransaction();
//		return person;
//	}
}